#!/usr/bin/zsh

print_info(){
	echo -e "\033[32m $1 \033[0m"
}

print_error(){
	echo -e "\033[31m $1 \033[0m"
}



install_font(){
	print_info "installing fonts"
	sudo apt-get install -y fonts-powerline
	fonts_dir=~/.local/share/fonts
	if [[ ! -d ${fonts_dir} ]]
	then
		mkdir ${fonts_dir} && cp Hack/* fonts_dir && fc-cache
	else
		cp Hack/* ${fonts_dir} && fc-cache
	fi
	
}

download_p10k(){
	print_info "downloading p10k theme"
	p10k_dir=~/.oh-my-zsh/themes/powerlevel10k
	if [[ ! -d ${p10k_dir} ]]
	then
		git clone --depth=1 https://gitee.com/gentlecp/powerlevel10k.git ${p10k_dir}
	else
		print_info "already exist"
	fi
}

download_zsh_autosuggestions(){
	print_info "downloading zsh_autosuggestions"
	auto_dir=~/.oh-my-zsh/custom/plugins/zsh-autosuggestions
	if [[ ! -d ${auto_dir} ]]
	then
		git clone --depth=1 https://gitee.com/gentlecp/zsh-autosuggestions ${auto_dir}
	else
		print_info "already exist"
	fi
}

download_zsh_syntax_highlighting(){
	print_info "downloading zsh_syntax_highlighting"
	high_dir=~/.oh-my-zsh/custom/plugins/zsh-syntax-highlighting
	if [[ ! -d ${high_dir} ]]
	then
		git clone --depth=1 https://gitee.com/gentlecp/zsh-syntax-highlighting.git ${high_dir}
	else
		print_info "already exist"
	fi

}

set_zsh_config(){
	print_info "set zsh config"
	sudo cp ~/.zshrc ~/.zshrc.bak
	sudo cp zshrc ~/.zshrc && source ~/.zshrc
}

main(){
	if [ ! -d ~/.oh-my-zsh ];
	then
		print_error "can not find oh my zsh, please run 2.install_ohmyzsh.sh at first"
	else
		install_font
		download_p10k
		download_zsh_autosuggestions
		download_zsh_syntax_highlighting
		set_zsh_config
	fi
}

main

